package com.webchat.connect.messagequeue.consumer.redis;

import com.webchat.connect.messagequeue.consumer.service.GroupVideoCallConsumeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class GroupVideoCallRedisQueueListener implements MessageListener {


    @Autowired
    private GroupVideoCallConsumeService groupVideoCallConsumeService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void onMessage(Message message, byte[] pattern) {

        String channel = (String) redisTemplate.getStringSerializer().deserialize(message.getChannel());
        String messageStr = (String) redisTemplate.getValueSerializer().deserialize(message.getBody());
        log.info("ChatMessageNotifyQueueListener.onMessage =====> channel:{} messageStr:{}", channel, messageStr);

        groupVideoCallConsumeService.consume(messageStr);
    }
}
